//Proxy对象（代理）:监视对象的属性的读写
/**
 * Proxy对象的参数：1.目标对象，2.操作对象
 * target:目标对象  property：属性  value：值
 * 操作对象有两个方法，get(target,property)和set(target,property,value)
 */

const person = {
  name: "tom",
  age: 18,
};

const personProxy = new Proxy(person, {
  get(target, property) {
    console.log(target, property);
    return property in target ? property : undefined;
  },
  set(target, property, value) {
    target[property] = value;
  },
});

// console.log(personProxy.name);
// console.log(personProxy.sex);
personProxy.sex = "男";
console.log(person);
